<?php
//week string
$week_array = BUtils::WeekDayKeys(7, true);

//set offer picture
$url_thumb_default = Yii::app()->baseUrl . '/img/default_special_thumb.png';
$url_picture_default = Yii::app()->baseUrl . '/img/default_special_picture.png';
$url_thumb = empty($r['url_picture']) ? $r['url_offer_img'] : $r['url_picture'];
if (!empty($url_thumb)) {
	$url_thumb = BUtils::GetOfferThumbUrl($url_thumb);
	$url_picture = str_replace('thumb_', '', $url_thumb);
} else {
	$url_thumb = $url_thumb_default;
	$url_picture = $url_picture_default;
}

//set price, discount or highlight
$highlight = $del_price = '';
if (!empty($r['price'])) {
	$highlight = MerchantObject::formatPrice($r['price']);
	if (!empty($r['value'])) {
		$del_price = '<span class="oldprice label">€'.$r['value'].'</span>';
	}
} elseif (!empty($r['discount'])) {
	$highlight = MerchantObject::formatDiscount($r['discount']);
}

//define hours list of offer
$a24Hours = BUtils::AllHour24();
$hours_list = MerchantObject::HtmlOfferHours($offer_hours, $week_array, $a24Hours);

//set day string
$week_string = BUtils::GetWeekdays($r['week_days'], $week_array);
$range_date = BUtils::GetRecentDayName($r['week_days'], $week_string, false, $r['start_hour']);
$range_time = BUtils::GetHourRangeFormat($r['start_hour'], $r['end_hour'], $r['show_hours']);

//set date range
$valid_peroid = BUtils::GetDateRangeString($r['uts_start_date'], $r['uts_end_date']);

//business icon url
$biz_icon = Yii::app()->baseUrl . '/img/icons/icon_others.png';
if (!empty($r['category_key'])) {
	$biz_icon = Yii::app()->baseUrl . '/img/icons/icon_'.$r['category_key'].'.png';
}

//offer content
$content = nl2br(strip_tags(trim($r['content'])));

$max_number_msg = '';
if ($r['max_number'] > 0) {
	$max_number_msg = '<div class="remaining">' . BUtils::T('offer_remaining_lbl', array('{number}' => $r['max_number'])) . '</div>';
}

//address
$biz_address = '';
if (!empty($r['address'])) {
	$biz_address = $r['address'];
	if (!empty($r['postcode'])) $biz_address .= '<br />' . $r['postcode'] . ' ' . $r['city'];
}

//how to use tips
if ($r['redeem_type'] == 2) {
	$how_to_redeem_icon = '<img src="'.Yii::app()->baseUrl.'/img/icons/using_show.png" alt="" />';
	$how_to_redeem_btn = '';
	$how_to_redeem_msg = BUtils::T('special_using_show_lbl');
} elseif ($r['redeem_type'] == 1) {
	$how_to_redeem_icon = '<img src="'.Yii::app()->baseUrl.'/img/icons/using_show.png" alt="" />';
	$how_to_redeem_btn = '<button class="btn btn-primary btn-small" rel="tipsy" title="'.BUtils::T('user_click_redeem_tips').'">'.BUtils::T('redeem_btn').'</button>';
	$how_to_redeem_msg = BUtils::T('special_using_click_lbl');
} else {
	$how_to_redeem_icon = '<img src="'.Yii::app()->baseUrl.'/img/icons/using_scan.png" alt="" />';
	$how_to_redeem_btn = '<button class="btn btn-primary btn-small" rel="tipsy" title="'.BUtils::T('user_scan_redeem_tips').'">'.BUtils::T('scan_btn').'</button>';
	$how_to_redeem_msg = BUtils::T('special_using_scan_lbl');
}
?>
<div class="offer_v2" style="width:auto;">
	<div class="offer-header relative">
		<img src="<?php echo $url_picture; ?>" alt="" onError="this.onerror=null;this.src='<?php echo Yii::app()->baseUrl; ?>/img/default_special_picture.png';" />
		<div class="info">
			<div class="mb_price">
				<div class="highlight"><?php echo $highlight; ?></div>
				<?php echo $del_price; ?>
			</div>
			<div class="mb_period">
				<div class="time"><?php echo $range_time; ?></div>
				<div class="date"><?php echo $range_date; ?></div>
			</div>
			<div class="clearfix"></div>
		</div>
	</div>
	<div class="action">
		<div class="margin">
			<div class="icon"><?php echo $how_to_redeem_icon; ?></div>
			<div class="redeem_button"><?php echo $how_to_redeem_btn; ?></div>
			<div class="tips"><?php echo $how_to_redeem_msg; ?></div>
			<div class="clearfix"></div>
		</div>
	</div>
	<ul class="offer-detail">
		<li class="field clearfix">
			<i class="sign icon-time icon-2x"></i>
			<div class="desc">
				<span><?php echo $hours_list; ?></span>
				<hr class="hr-2" />
				<span><?php echo $valid_peroid; ?></span>
			</div>
		</li>
		<li class="field clearfix">
			<i class="sign icon-map-marker icon-2x"></i>
			<div class="desc">
				<?php echo $biz_address; ?>
			</div>
		</li>
		<li class="field clearfix">
			<div id="special-content"><?php echo $content; ?></div>
		</li>
	</ul>
	<?php echo $max_number_msg; ?>
</div>